var oTimer = null;
var hasUpload = false;
function getProgress() {
	$.getJSON(path + "/fileStatus", {stamp: new Date().getTime()}, function(data) {
		//$("#attachment").html('已上传'+data.mbRead+'MB  速度：'+data.speed+'KB/s  进度：'+data.percent);
		var percent = data.percent;
		var num = percent.substring(0, percent.length - 1);
		if (0 <= num <= 100) {
			var html = '<div class="progress-bar" role="progressbar" aria-valuenow="'+num+'" aria-valuemin="0" aria-valuemax="100" style="width: '+percent+';">';
			html += percent;
			html += '</div>';
			$(".progress").show();
			$(".progress").html(html);
		}
	});
}
function clean() {
	hasUpload = false;
	window.clearInterval(oTimer);
	//$("#attachment").html('');
	$(".progress").html('');
	$(".progress").hide();
}
function ajaxFileUpload(id) {
	hasUpload = true;
	$.ajaxFileUpload({
		url: path + "/file/apiUpload",
		type: 'post',
		secureuri: false,
		fileElementId: id,
		dataType: 'json',
		success: function(data) {
			if (data.statusCode == statusCode.ok) {
				//success(data.message);
				$("input[name=url]").val(data.data.url);
				hasUpload = false;
				window.clearInterval(oTimer);
				//$("#attachment").html('<a href="'+path+'/file/download?url='+data.data.url+'">'+data.data.fileName+'</a>');
			} else if (data.statusCode == statusCode.error) {
				error(data.message);
				clean();
			} else {
				clean();
			}
		},
	    error: function(data, status, e){
			error(data.responseText);
			clean();
	    }
	});
}